home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Best of MacTutor - S…e Code for Volumes 1 to 5
/
The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin
/
Source Code
/
#41 (Feb 89)
/
vblTask code
/
vblTask.c
< prev
next >
Wrap
C/C++ Source or Header
|
1988-10-14
|
5KB
|
157 lines
/************************************************************************************************
* vblTask.c *
* an VBL task animation example *
* *
* Written by Dick Chandler *
* *
* This program is intentionally keep as simple as possible, so that it could be *
* easily entered and/or understood. Therefore there are no calls made to check *
* events nor any menus implemented. *
* *
*************************************************************************************************/
/***** the only includes we'll need *****/
#include <types.h>
#include <quickdraw.h>
#include <windows.h>
#include <toolutils.h>
#include <events.h>
#include <Retrace.h>
#include <OSUtils.h>
#include <Strings.h>
/***** we need to define our own 'A5' routines *****/
pascal void SetUpA5a() extern 0x2f0d;
pascal void SetUpA5b() extern 0x2a78;
pascal void SetUpA5c() extern 0x0904;
#define SetUpA5() SetUpA5a(); SetUpA5b(), SetUpA5c()
pascal void RestoreA5() extern 0x2a5f;
/* just for readibilty */
#define NOT !
/***** Globals *****/
Rect iconRec = { 30, 30, 62, 62 }; /* location of pause icon */
Rect boundsRect = { 30, 30, 120, 120 }; /* window rectangle */
VBLTask StatusTask; /* tasks VBL record */
void vblTask(), installTask(), removeTask(); /* task routines */
long interval; /* time between icons */
/***** constants *****/
#define FIRST_ICON 1000
#define LAST_ICON 1005
#define MAX_NUMBER_ICONS (LAST_ICON - FIRST_ICON) +1
#define SECONDS 60
/************************************************************************************************
* the main program *
*************************************************************************************************/
int main()
{
WindowRecord editWindowRecord;
WindowPtr editWindowPtr;
/*
* the init's we need
*/
InitGraf (&qd.thePort); /* init quickdraw */
InitWindows (); /* init the window manager */
/*
* open a small, simple (and humble) window
*/
editWindowPtr = NewWindow(&editWindowRecord, &boundsRect, "",
true, 1, (-1), false, nil);
SetPort ( editWindowPtr );
/*
* set task icons in motion
*/
interval = SECONDS/8; /* set the interval between icons */
installTask ( &StatusTask ); /* install our task on vbl queue */
/*
* run until the button is clicked
*/
while ( NOT Button() )
;
/*
* clean up and exit
*/
removeTask (); /* remove our task on vbl queue */
CloseWindow (editWindowPtr); /* flush window memory */
return 0; /* MPW Return */
}
/************************************************************************************************
* NAME: installTask
*
* INPUT: StatusTaskPtr - a pointer to a VBL task record
*
* FUNCTION: installs our vblTask after seting the vbl parameters
*
*************************************************************************************************/
void installTask( StatusTaskPtr )
VBLTask *StatusTaskPtr; /* tasks VBL record */
{
StatusTaskPtr->vblAddr = vblTask; /* set to out task function */
StatusTaskPtr->vblCount = 10; /* set initial time to 10 ticks */
StatusTaskPtr->vblPhase = 0; /* no offset needed */
StatusTaskPtr->qType = vType; /* type VBL task */
VInstall (StatusTaskPtr); /* now install the task */
}
/************************************************************************************************
* NAME: removeTask
*
* INPUT: StatusTask - a pointer to a VBL task record
*
* FUNCTION: removes our vbl task
*
*************************************************************************************************/
void removeTask( StatusTaskPtr )
VBLTask *StatusTaskPtr; /* tasks VBL record */
{
VRemove (StatusTaskPtr); /* remove task from VBL */
}
/************************************************************************************************
* NAME: vblTask
*
* FUNCTIONS: our actual vbl task which gets called every 'interval' ticks
*
*************************************************************************************************/
void vblTask()
{
static long icons;
Handle tempIcon; /* handle to icon */
static long timeIcon = FIRST_ICON;
SetUpA5(); /* set up A5 register */
icons = MAX_NUMBER_ICONS;
StatusTask.vblCount = interval; /* reset task to correct time */
timeIcon++; /* increment icon */
if ( timeIcon > LAST_ICON )
timeIcon = FIRST_ICON;
tempIcon = GetIcon( timeIcon );
if ( tempIcon )
PlotIcon( &iconRec, tempIcon );
RestoreA5(); /* preserve A5 register */
}